<template>
  <div v-if="Object.keys(detailGoodsInfo).length !== 0" class="detail-goods-info">
    <div class="info-desc">
      <span class="start"></span>
      <div class="desc">{{ detailGoodsInfo.desc }}</div>
      <span class="end"></span>
    </div>

    <div class="info-key">{{ detailGoodsInfo.detailImage[0].key }}</div>

    <div class="info-list">
      <img v-for="(item,index) in detailGoodsInfo.detailImage[0].list" :key="index"
           :src="item" @load="detailImgLoad" alt="">
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailGoodsInfo",
  props: {
    detailGoodsInfo: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      counter: 0,
      imagesLength: 0
    }
  },
  methods: {
    detailImgLoad() {
      this.counter += 1
      if (this.counter === this.imagesLength) {
        this.$emit('detailImgLoad')
      }
    }
  },
  watch: {
    detailGoodsInfo() {
      // 获取图片的个数，只会执行一次，除非图片有变化
      this.imagesLength = this.detailGoodsInfo.detailImage[0].list.length
    }
  }
}
</script>

<style scoped>
.detail-goods-info {
  padding: 30px 0;
  border-bottom: 5px solid #f2f5f8;
}

.info-desc {
  padding: 0 20px;
}

.info-desc .start, .info-desc .end {
  width: 90px;
  height: 1px;
  background-color: #a3a3a5;
  position: relative;
}

.info-desc .start {
  float: left;
}

.info-desc .end {
  float: right;
}

.info-desc .start::before, .info-desc .end::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  background-color: #333;
  bottom: 0;
}

.info-desc .end::after {
  right: 0;
}


.info-desc .desc {
  padding: 15px 0;
  font-size: 14px;
}

.info-key {
  font-weight: bold;
  color: #333;
  font-size: 15px;
  border-bottom: 1px solid #333;
  display: inline-block;
  padding-bottom: 3px;
  margin: 10px 0 0 15px;
}

.info-list img {
  width: 100%;
}
</style>
